package com.vislardo.app.notebook.model;

import cn.hutool.json.JSONUtil;
import lombok.Data;

import java.util.Map;
@Data
public class NoteInfo {

    private String noteCode;

    private String noteName;
    private String noteKey;
    private String oldNoteKey;

    public NoteInfo(String jsonStr) {
        Map<String,Object> value_map = JSONUtil.toBean(jsonStr,Map.class);
        this.noteCode = value_map.get("noteCode").toString();
        this.noteName = value_map.get("noteName").toString();
        this.noteKey = value_map.getOrDefault("noteKey","").toString();
        this.oldNoteKey = value_map.getOrDefault("oldNoteKey","").toString();
    }



    public NoteInfo(){}
//    public NoteInfo(String code, String noteKey, String oldNoteKey) {
//        this.noteCode = code;
//        this.noteKey = noteKey;
//        this.oldNoteKey = oldNoteKey;
//    }

    public String toString(){
        return JSONUtil.parseObj(this).toString();
    }

    public String setNewKey(String key){
        this.oldNoteKey = this.noteKey;
        this.noteKey = key;
        return this.toString();
    }

    public static NoteInfo getTestNote(){
        NoteInfo note = new NoteInfo();
        note.setNoteCode("test_note_book");
        note.setNoteName("测试");
        note.setNoteKey("");
        note.setOldNoteKey("");
        return note;
    }
}
